<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/vant@1.6/lib/index.css">
		<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.min.js"></script>
		<script src="https://cdn.jsdelivr.net/npm/vant@1.6/lib/vant.min.js"></script>
		<script src="../js/listener_other.js"></script>
		<script src="../js/ajax.js"></script>
		<title>修改手机号</title>
		<style>
			#spanber {
				background-color: red;
			}

			#spanber>.van-nav-bar__left>i,
			#spanber div,
			#spanber span {
				color: #fff;
			}
		</style>
	</head>
	<body>
		<div id="app">
			<van-row>
				<van-col span="24" id="spanber">
					<van-nav-bar id="spanber" title="修改手机号" left-arrow right-text="确认修改" @click-left="onClickLeft" @click-right="onClickRight">
					</van-nav-bar>
				</van-col>
				<van-col span="24">
					<van-cell-group>
						<van-field v-model="Phone" type="Number" placeholder="手机号码"></van-field>
						<van-cell-group>
							<van-field v-model="code" center clearable placeholder="验证码(6位数字短信验证码)">
								<van-button slot="button" @click="onCode" size="normal" type="danger">发送验证码</van-button>
							</van-field>
						</van-cell-group>
					</van-cell-group>
				</van-col>
			</van-row>
		</div>
		<script>			
			var vm = new Vue({
				el: "#app",
				data: {
					Phone: "",
					code: "",
				},
				methods: {
					onClickLeft() {
						plus.webview.close(plus.webview.currentWebview(), "slide-out-left");
					},
					onClickRight() {
						if (confirm('确定要更改吗') == true) {
							var _this = this
							ajax({
								url: "http://dsapi.ysd3g.com/api/ChangePhone",
								data: {
									key: localStorage.getItem('Key'),		
									Phone:_this.Phone,
									code: _this.code
								},
								dataType: "jsonp",
								success: function(res) {
									if (!res.Error) {
										var Phone=localStorage.getItem("Phone");
										Phone=_this.Phone;
										localStorage.setItem("Phone",Phone);
										plus.webview.getWebviewById("profile").reload(true);
										alert("修改成功")									
										plus.webview.close(plus.webview.currentWebview());										
									} else {
										alert(res.Msg)
									}
								}
							})
						} else {
							alert("已取消更改")
						}
					},
					//获取验证码
					onCode: function(data) {
						var _this = this;
						ajax({
							url: "http://dsapi.ysd3g.com/api/SendChangePhoneCode",
							dataType: "jsonp",
							data: {
								Phone: _this.Phone,
								key:localStorage.getItem('Key')
							},
							success: function(res) {
								console.log(res)
								_this.code = res.Code;
// 								console.log(res.Code)
								_this.$toast(_this.code);
							}
						})
					},
				},
				mounted() {
					this.Phone = localStorage.getItem('Phone')
				}
			})
		</script>
	</body>
</html>